package test

import java.io.File
import implicits.Implicits._

/**
 * Created by yz on 16/12/2021
 */
object DealAnno {

  def main(args: Array[String]): Unit = {
    //    or

    val parentDir = new File("E:\\snp_database\\test")
    val koDir = new File(parentDir, "ko")
    val annoDir = new File(parentDir, "anno")
    val rs = annoDir.myListFiles.filter { dir =>
      val file = new File(dir, s"or.txt")
      file.exists()
    }.foreach { dir =>
      val file = new File(dir, s"or.txt")
      file.txtLines.foreach { columns =>
        val kId = columns(0).mySplit(":").last
        new File(koDir, s"${kId}.txt").fileCopyToDir(dir)
      }
    }

  }

  def notBlankOr = {
    val parentDir = new File("E:\\snp_database\\test")
    val annoDir = new File(parentDir, "anno")
    annoDir.myListFiles.filterNot { dir =>
      val file = new File(dir, s"${dir.getName}_or.txt")
      file.str.isBlank
    }.foreach { dir =>
      val file = new File(dir, s"${dir.getName}_or.txt")
      val destFile = new File(dir, s"not_blank_or.txt")
      file.copyTo(destFile)
    }
  }

  def or = {
    val parentDir = new File("E:\\snp_database\\test")
    val annoDir = new File(parentDir, "anno")
    annoDir.myListFiles.filter { dir =>
      val file = new File(dir, s"not_blank_or.txt")
      file.exists()
    }.filter { dir =>
      val file = new File(dir, s"not_blank_or.txt")
      file.txtLines.exists { columns =>
        val vs = columns(1).mySplit("[;]").map(_.trim)
        vs.exists(_ == dir.getName)
      }
    }.foreach { dir =>
      val file = new File(dir, s"not_blank_or.txt")
      val destFile = new File(dir, s"or.txt")
      file.txtLines.filter { columns =>
        val vs = columns(1).mySplit("[;]").map(_.trim)
        vs.exists(_ == dir.getName)
      }.toTxtFile(destFile)
    }
  }



}
